import {type AxiosResponse, vCairnRequest} from 'v-cairn';
import type { VCairnConfig } from 'v-cairn';
import type { App } from 'vue';

const axiosConfig = {
    timeout: 30000,
    baseURL: 'http://ea.equali.cn:4082/api/platform',
    withCredentials: true
};


export function startVCairn(app: App) {
    const vCairnConfig:VCairnConfig = {
        axiosConfig,
        // http 是2xx时，根据业务数据的code来判断哪些业务数据是可以用的
        hasErrorInSuccess: (response: AxiosResponse) => {
            return response.data.code !== 200;
        },
        specifiedErrorCodes: {
            '500': {
                handler: (code, response) => {
                    alert(code+': '+response.data.message);
                }
            }
        }
    };
    app.use(vCairnRequest, vCairnConfig);
}